﻿using System;
using System.Drawing;

namespace TeslaSamples {
    [AttributeUsage(AttributeTargets.Class)]
    public sealed class AppDescriptionAttribute : Attribute {
        public readonly String Name;
        public readonly PlatformCapabilities Platforms;
        public readonly Image Thumbnail;
        public readonly String RTFDescription;
        public readonly String RTFSource;

        public AppDescriptionAttribute(String name, PlatformCapabilities platforms) {
            Name = name;
            Platforms = platforms;
            Thumbnail = Resources.DefaultImage;
            RTFDescription = Resources.NoDescription;
            RTFSource = Resources.NoSourceCode;
        }

        public AppDescriptionAttribute(String name, PlatformCapabilities platforms, String descFile) {
            Name = name;
            Platforms = platforms;
            Thumbnail = Resources.DefaultImage;
            if(descFile != null) {
                RTFDescription = Resources.ResourceManager.GetString(descFile);
                if(RTFDescription == null) {
                    RTFDescription = Resources.NoDescription;
                }
            } else {
                RTFDescription = Resources.NoDescription;
            }
            RTFSource = Resources.NoSourceCode;
        }

        public AppDescriptionAttribute(String name, PlatformCapabilities platforms, String thumbnail, String descFile, String sourceFile) {
            Name = name;
            Platforms = platforms;
            if(thumbnail != null) {
                Thumbnail = (Image) Resources.ResourceManager.GetObject(thumbnail);
                if(Thumbnail == null) {
                    Thumbnail = Resources.DefaultImage;
                } 
            } else {
                Thumbnail = Resources.DefaultImage;
            }

            if(descFile != null) {
                RTFDescription = Resources.ResourceManager.GetString(descFile);
                if(RTFDescription == null) {
                    RTFDescription = Resources.NoDescription;
                }
            } else {
                RTFDescription = Resources.NoDescription;
            }

            if(sourceFile != null) {
                RTFSource = Resources.ResourceManager.GetString(sourceFile);
                if(RTFSource == null) {
                    RTFSource = Resources.NoSourceCode;
                }
            } else {
                RTFSource = Resources.NoSourceCode;
            }
        }
    }
}
